<template>
  <a-modal :visible="true" :footer="null" :width="700" @cancel="cancelEvent" class="orderModal">
    <div class="infoModal">在线率标准视频</div>
    <a-form-model
      style="margin-right:10px"
      ref="ruleForm"
      :rules="rules"
      :model="form"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
      class="formVideoModel"
    >
      <a-row>
        <a-col :span="12">
          <a-form-model-item ref="country" label="区县" prop="country" v-if="showCountry">
            <CountySelect :form.sync="form" @update="validateField"></CountySelect>
          </a-form-model-item>
          <a-form-model-item label="区县" v-if="!showCountry">
            <a-select v-model="form.country" :disabled="true"></a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="监控量" ref="monitorNum" prop="monitorNum">
            <a-input v-model="form.monitorNum" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="离线量" ref="offlineNum" prop="offlineNum">
            <a-input v-model="form.offlineNum" />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="在线量" ref="onlineNum" prop="onlineNum">
            <a-input v-model="form.onlineNum" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="在线率" ref="onlineRate" prop="onlineRate">
            <a-input v-model="form.onlineRate" />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="8小时内修复量" ref="repairEightNum" prop="repairEightNum">
            <a-input v-model="form.repairEightNum" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="已修复总量" ref="repairNum" prop="repairNum">
            <a-input v-model="form.repairNum" />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="故障修复及时率" ref="repairRate" prop="repairRate">
            <a-input v-model="form.repairRate" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-form-model-item :wrapper-col="{ span: 24, offset: 10 }">
        <a-button type="primary" @click="onSubmit">
          提交
        </a-button>
        <a-button style="margin-left: 10px;" @click="cancelEvent">
          取消
        </a-button>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import { modifyLineVideo } from '@/api/video'
import CountySelect from '@/views/videoManage/util/countySelect'
import { ACCESS_TOKEN, ROLE_NAME, USERINFO } from '@/store/mutation-types'
import Vue from 'vue'
export default {
  props: ['info'],
  components: { CountySelect },
  data() {
    return {
      showCountry: true,
      labelCol: { span: 8 },
      wrapperCol: { span: 14 },
      form: {},
      rules: {
        country: [{ required: true, message: '请选择区县', trigger: 'change' }],
        onlineNum: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        offlineNum: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        onlineRate: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        repairEightNum: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        repairNum: [{ required: true, message: '请输入完整', trigger: 'blur' }],

        repairRate: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        level: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        lightCross: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        number: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        olt: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        poleNo: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        probeType: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        poleType: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        police: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        monitorNum: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        route: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        siteName: [{ required: true, message: '请输入完整', trigger: 'blur' }],
        siteNo: [{ required: true, message: '请输入完整', trigger: 'blur' }],

        customerMobile: [
          { required: true, message: '请输入电话', whitespace: true },
          { validator: this.phoneCheck.bind(this) }
        ]
      }
    }
  },
  created() {
    if (Vue.ls.get(ROLE_NAME) == '区县公司') {
      this.form.country = Vue.ls.get(USERINFO).belong
      this.showCountry = false
    } else if (Vue.ls.get(ROLE_NAME) == '市公司') {
    } else if (Vue.ls.get(ROLE_NAME) == '代维单位') {
      this.form.country = Vue.ls.get(USERINFO).belong
      this.form.memberId = Vue.ls.get(USERINFO).id
      this.showCountry = false
    } else if (Vue.ls.get(ROLE_NAME) == '管理员') {
    }
  },
  mounted() {
    this.form = JSON.parse(JSON.stringify(this.info))
  },
  methods: {
    //手动再验证
    validateField(e) {
      this.form.country = e
      this.$refs.ruleForm.validateField('country')
    },
    onSubmit() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          // console.log("22222")

          modifyLineVideo(this.form).then(response => {
            if (response != undefined) {
              if (response.code == 200) {
                let type = 'success'
                this.$notification[type]({
                  message: '温馨提示',
                  description: '编辑成功!',
                  duration: 3
                })
                this.$emit('successEvent')
              }
            }
          })
        } else {
          return false
        }
      })
    },
    cancelEvent() {
      this.$emit('cancelEvent')
    },
    phoneCheck(rule, value, callbackFn) {
      const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
      if (!reg.test(value)) {
        callbackFn('手机号码格式不正确')
        return
      }
      callbackFn()
    }
  }
}
</script>
